# -*- coding: utf-8 -*-
=begin
  Copyright (C) 2014 Takashi SUGA

  You may use and/or modify this file according to the license
  described in the LICENSE.txt file included in this archive.
=end

module MiniTest

  class Yerm < MiniTest::TestCase
    Abbrs    = [[], 21, [21,14], [21,14, 5]]
    Crecents = %w<
      -1(02(03(04
      20(02(03(04
      -1-02(03(04
      20-02(03(04
      -1-02(03
      20-02(03
      -1-02
      20-02
      -1-
      20-
      -1
         02(03(04
            03(04
               04
     04)03)02)-1
     04)03)02)20
     04)03)02--1
     04)03)02-20
        03)02--1
        03)02-20
           02--1
     04)03)02
     04)03
     20-23)08)14
     20-23)08
    >
    Results = [
      [[], "-1(02(03(04", "-1-02-03-04"],
      [[], "20(02(03(04", "20-02-03-04"],
      [[], "-1-02(03(04", "-1-02-03-04"],
      [[], "20-02(03(04", "20-02-03-04"],
      [[], "-1-02(03", "-1-02-03"],
      [[], "20-02(03", "20-02-03"],
      [[], "-1-02", "-1-02"],
      [[], "20-02", "20-02"],
      [[], "-1-", "-1"],
      [[], "20-", "20"],
      [[], "-1", "-1"],
      [[], "02(03(04", :error],
      [[], "03(04", :error],
      [[], "04", :error],
      [[], "04)03)02)-1", "-1-02-03-04"],
      [[], "04)03)02)20", "20-02-03-04"],
      [[], "04)03)02--1", "-1-02-03-04"],
      [[], "04)03)02-20", "20-02-03-04"],
      [[], "03)02--1", "-1-02-03"],
      [[], "03)02-20", "20-02-03"],
      [[], "02--1", "-1-02"],
      [[], "04)03)02", :error],
      [[], "04)03", :error],
      [[], "20-23)08)14", "20-14-08-23"],
      [[], "20-23)08", :error],
      [21, "-1(02(03(04", "-1-02-03-04"],
      [21, "20(02(03(04", "20-02-03-04"],
      [21, "-1-02(03(04", "-1-02-03-04"],
      [21, "20-02(03(04", "20-02-03-04"],
      [21, "-1-02(03", "-1-02-03"],
      [21, "20-02(03", "20-02-03"],
      [21, "-1-02", "-1-02"],
      [21, "20-02", "20-02"],
      [21, "-1-", "-1"],
      [21, "20-", "20"],
      [21, "-1", "-1"],
      [21, "02(03(04", "21-02-03-04"],
      [21, "03(04", :error],
      [21, "04", :error],
      [21, "04)03)02)-1", "-1-02-03-04"],
      [21, "04)03)02)20", "20-02-03-04"],
      [21, "04)03)02--1", "-1-02-03-04"],
      [21, "04)03)02-20", "20-02-03-04"],
      [21, "03)02--1", "-1-02-03"],
      [21, "03)02-20", "20-02-03"],
      [21, "02--1", "-1-02"],
      [21, "04)03)02", "21-02-03-04"],
      [21, "04)03", :error],
      [21, "20-23)08)14", "20-14-08-23"],
      [21, "20-23)08", :error],
      [[21, 14], "-1(02(03(04", "-1-02-03-04"],
      [[21, 14], "20(02(03(04", "20-02-03-04"],
      [[21, 14], "-1-02(03(04", "-1-02-03-04"],
      [[21, 14], "20-02(03(04", "20-02-03-04"],
      [[21, 14], "-1-02(03", "-1-02-03"],
      [[21, 14], "20-02(03", "20-02-03"],
      [[21, 14], "-1-02", "-1-02"],
      [[21, 14], "20-02", "20-02"],
      [[21, 14], "-1-", "-1"],
      [[21, 14], "20-", "20"],
      [[21, 14], "-1", "-1"],
      [[21, 14], "02(03(04", "21-02-03-04"],
      [[21, 14], "03(04", "21-14-03-04"],
      [[21, 14], "04", :error],
      [[21, 14], "04)03)02)-1", "-1-02-03-04"],
      [[21, 14], "04)03)02)20", "20-02-03-04"],
      [[21, 14], "04)03)02--1", "-1-02-03-04"],
      [[21, 14], "04)03)02-20", "20-02-03-04"],
      [[21, 14], "03)02--1", "-1-02-03"],
      [[21, 14], "03)02-20", "20-02-03"],
      [[21, 14], "02--1", "-1-02"],
      [[21, 14], "04)03)02", "21-02-03-04"],
      [[21, 14], "04)03", "21-14-03-04"],
      [[21, 14], "20-23)08)14", "20-14-08-23"],
      [[21, 14], "20-23)08", :error],
      [[21, 14, 5], "-1(02(03(04", "-1-02-03-04"],
      [[21, 14, 5], "20(02(03(04", "20-02-03-04"],
      [[21, 14, 5], "-1-02(03(04", "-1-02-03-04"],
      [[21, 14, 5], "20-02(03(04", "20-02-03-04"],
      [[21, 14, 5], "-1-02(03", "-1-02-03"],
      [[21, 14, 5], "20-02(03", "20-02-03"],
      [[21, 14, 5], "-1-02", "-1-02"],
      [[21, 14, 5], "20-02", "20-02"],
      [[21, 14, 5], "-1-", "-1"],
      [[21, 14, 5], "20-", "20"],
      [[21, 14, 5], "-1", "-1"],
      [[21, 14, 5], "02(03(04", "21-02-03-04"],
      [[21, 14, 5], "03(04", "21-14-03-04"],
      [[21, 14, 5], "04", "21-14-5-04"],
      [[21, 14, 5], "04)03)02)-1", "-1-02-03-04"],
      [[21, 14, 5], "04)03)02)20", "20-02-03-04"],
      [[21, 14, 5], "04)03)02--1", "-1-02-03-04"],
      [[21, 14, 5], "04)03)02-20", "20-02-03-04"],
      [[21, 14, 5], "03)02--1", "-1-02-03"],
      [[21, 14, 5], "03)02-20", "20-02-03"],
      [[21, 14, 5], "02--1", "-1-02"],
      [[21, 14, 5], "04)03)02", "21-02-03-04"],
      [[21, 14, 5], "04)03", "21-14-03-04"],
      [[21, 14, 5], "20-23)08)14", "20-14-08-23"],
      [[21, 14, 5], "20-23)08", :error]]

    def test__parse_crecents
      results = []
      Abbrs.each do |abbr|
        Crecents.each do |crecent|
          begin
            results << [abbr, crecent, When::CalendarTypes::Yerm.parse(crecent, abbr)]
          rescue
            results << [abbr, crecent, :error]
          end
        end
      end
      assert_equal(Results, results)
    end
  end
end
